package com.e.dianshang.controller;

import com.e.dianshang.pojo.Myeye;
import com.e.dianshang.service.MyeyeService;
import com.e.dianshang.service.OrderService;
import com.e.dianshang.utils.BusinessException;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Tian同學
 * @Date 2020/11/9 17:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/myeye")
@Api(value = "移动到关注",tags = "移动到关注的api")
public class MyeyeController {

    @Resource
    MyeyeService myeyeService;

    @Resource
    OrderService orderService;

    @PostMapping("/insertMyeye")
    @ApiOperation(value = "移动到关注",httpMethod = "POST")
    public Map delete(@RequestBody @ApiParam(value = "移入到关注的json数据",required = true) List<Myeye> myeye) throws BusinessException {

        JsonResult jsonResult=new JsonResult();

        int i=0;

        for (Myeye myeye1 : myeye) {
            i = myeyeService.insertMyeye(myeye1);
            orderService.delete(myeye1.getId());
        }

        if (i>0){
            jsonResult.setCode("0");
            jsonResult.setMsg("移入成功！！");
        }else {
            throw new BusinessException("移入失败！！");
        }

        return jsonResult.getValues();

    }
}
